﻿/*-----------------------------------------------------------------------
 * <copyright file="WCFOPCorrelation.svc.cs" company="O-RID">
 *     Copyright (c)2010 O-RID Co.,Ltd.
 * </copyright>
 * <author>Zhang Jun</author>
 * <summary>
 *          所有无法归类的查询 服务
 *          StatisticsToolsDB_new 数据库
 *
 *          作成日：07/27/2010
 *          06/29/2011 增加 ParintID查询信息
 *          
 * </summary>
 *-----------------------------------------------------------------------
 */
namespace Orid.Management.Statistics.Service.OPUnitService.TheOthersQuery
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.ServiceModel.Activation;
    using Orid.Management.Statistics.Service.OPUnitService.TheOthersQuery.ServiceModel;

    /// <summary>
    ///  注意: 如果更改此处的类名 "WCFTheOthersQuery"，也必须更新 Web.config 中对 "WCFTheOthersQuery" 的引用。
    /// </summary>
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class WCFTheOthersQuery : IWCFTheOthersQuery
    {
        #region  OP权限查询
        /// <summary>
        /// OP权限查询
        /// OPRolesQueryControl.xaml
        /// </summary>
        /// <param name="WhereParameter">The where parameter.</param>
        /// <returns></returns>
        public List<OperatorRolesData> SelectOperatorRolesQueryInfor(List<WhereParameters> whereParameter)
        {
            try
            {
                #region 参数形式转换
 
                // Server
                if (String.IsNullOrEmpty(whereParameter[0].WhereServer))
                {
                    whereParameter[0].WhereServer = string.Empty;
                }
                else
                {
                    whereParameter[0].WhereServer = whereParameter[0].WhereServer.ToString().Trim();
                }

                // Unit
                if (String.IsNullOrEmpty(whereParameter[0].WhereUnit))
                {
                    whereParameter[0].WhereUnit = string.Empty;
                }
                else
                {
                    whereParameter[0].WhereUnit = whereParameter[0].WhereUnit.ToString().Trim();
                }

                // OPID
                if (String.IsNullOrEmpty(whereParameter[0].WhereOpID))
                {
                    whereParameter[0].WhereOpID = string.Empty;
                }
                else
                {
                    whereParameter[0].WhereOpID = whereParameter[0].WhereOpID.ToString().Trim();
                }

                #endregion

                return DataProvider.GetSelectOperatorRolesQueryInfor(whereParameter);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFTheOthersQuery SelectOperatorRolesQueryInfor Error:" + ex.Message);
            }

            return null;
        }
        #endregion  OP权限查询

        #region 数据抽取

        /// <summary>
        /// 基礎データ抽取
        /// </summary>
        /// <param name="wherePar">输入参数</param>
        /// <param name="isOrder">True：(オーダ完了)。False：(オーダ未完)</param>
        /// <returns></returns>
        /// <value>11/08/2010 add </value>
        public List<DataExtractionData> DataExtractionInfor(WhereParameters wherePar, bool isOrder) 
        {
            try
            {
                string strOrder = string.Empty;

                #region 参数形式转换

                // 开始日期
                if (!wherePar.WhereentryDateFrom.Equals("null"))
                {
                    wherePar.WhereentryDateFrom = wherePar.WhereentryDateFrom.ToString().Trim();
                }
                //结束日期
                if (!wherePar.WhereentryDateTo.Equals("null"))
                {
                    wherePar.WhereentryDateTo = wherePar.WhereentryDateTo.ToString().Trim();
                }


                // 是否 オーダ
                if (isOrder)
                {
                    //オーダ完了
                    strOrder = "IsOver";
                }
                else
                {
                    //オーダ未完
                    strOrder = "NotOver";
                }

                #endregion

                return DataProvider.GetDataExtractionInfor(wherePar, strOrder);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFTheOthersQuery DataExtractionInfor Error:" + ex.Message);
            }

            return null;
        }

        /// <summary>
        /// オーダ情報 抽取
        /// </summary>
        /// <param name="wherePar">输入参数</param>
        /// <returns></returns>
        /// <value>11/10/2010 add </value>
        public List<OrderDate> OrderInfo(WhereParameters wherePar) 
        {
            try
            {

                #region 参数形式转换

                // 开始日期
                if (!wherePar.WhereentryDateFrom.Equals("null"))
                {
                    wherePar.WhereentryDateFrom = wherePar.WhereentryDateFrom.ToString().Trim();
                }
                //结束日期
                if (!wherePar.WhereentryDateTo.Equals("null"))
                {
                    wherePar.WhereentryDateTo = wherePar.WhereentryDateTo.ToString().Trim();
                }
               
                #endregion

                return DataProvider.GetOrderInfo(wherePar);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFTheOthersQuery OrderInfor Error:" + ex.Message);
            }

            return null;
        }

        #endregion 数据抽取

        #region ParintID查询信息
        /// <summary>
        /// ParintID查询信息 V2.13
        /// </summary>
        /// <param name="wherePar">输入参数</param>
        /// <returns></returns>
        /// <value >06/29/2011 add </value>
        public List<ParentIDDate> SelectParentIDInfor(WhereParameters wherePar) 
        {
            try
            {

                #region 参数形式转换

                // 开始日期
                if (!wherePar.WhereentryDateFrom.Equals("null"))
                {
                    wherePar.WhereentryDateFrom = wherePar.WhereentryDateFrom.ToString().Trim();
                }
                //结束日期
                if (!wherePar.WhereentryDateTo.Equals("null"))
                {
                    wherePar.WhereentryDateTo = wherePar.WhereentryDateTo.ToString().Trim();
                }

                //@MatterID = NULL,
                if (String.IsNullOrEmpty(wherePar.WhereOpID))
                {
                    wherePar.WhereOpID = string.Empty;
                }
                else
                {
                    wherePar.WhereOpID = wherePar.WhereOpID.ToString().Trim();
                }

                //@Lines = NULL,
                if (String.IsNullOrEmpty(wherePar.WhereServer))
                {
                    wherePar.WhereServer = string.Empty;
                }
                else
                {
                    wherePar.WhereServer = wherePar.WhereServer.ToString().Trim();
                }
                
                //@UserOrder = NULL
                if (String.IsNullOrEmpty(wherePar.WhereUnit))
                {
                    wherePar.WhereUnit = string.Empty;
                }
                else
                {
                    wherePar.WhereUnit = wherePar.WhereUnit.ToString().Trim();
                }

                #endregion

                return DataProvider.GetParentIDInfor(wherePar);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFTheOthersQuery SelectParentIDInfor Error:" + ex.Message);
            }

            return null;
        }

        #endregion  ParintID查询信息

    }
}
